package com.tim.third.demo.printer.zw;


import org.apache.http.client.ClientProtocolException;

import java.io.IOException;
import java.util.Date;


public class PrinterUtilTest {
	
	void test() throws ClientProtocolException, IOException {
        String url = "http://api.zhongwuyun.com";
		Printer printer = new Printer();
		int time =Math.round(new Date().getTime()/1000);//时间戳
		String data = "测试";//打印内容
		printer.setAppid(0);//appid
		printer.setAppsecret("");//appsecret
		printer.setDeviceid("");//设备id
		printer.setDevicesecret("");//设备秘钥
		printer.setTimestamp(time);//时间戳
		printer.setData(data);
		String sign = PrinterUtil.getSign(printer);
		System.out.println("time："+time);
		System.out.println("url："+ PrinterUtil.percentEncode(data));
		System.out.println("sign："+sign);
		//请求数据
		String datas = "appid="+printer.getAppid()+"&sign="+sign+"&timestamp="+time+"&deviceid="+
		printer.getDeviceid()+"&devicesecret="+printer.getDevicesecret()+"&printdata="+ PrinterUtil.percentEncode(data);
        System.out.println(datas);
		PrinterUtil.sendPost(url, datas);
	}

}
